<?php
/**
 * 
 * Abstract representation of an Table in the database.
 * 
 * @author Denis
 *
 */
abstract class MySQL {
	
	public static function execute($query){
		if(!$result = mysql_query($query)){
			die("Could not execute query " . mysql_error());
		}
		return $result;
	}
	
	/**
	 * Returns an associative array
	 * @param unknown_type $query
	 */
	public static function getArrayObject($query){
		$array = new ArrayObject();
		$resource = self::execute($query);
		while($result = mysql_fetch_assoc($resource)){
			$array->append($result);
		}
		return $array;
	}
	
	/**
	 * Returns the first result of a resultset
	 * @param 
	 */
	public static function getFirstResult($query){
		$resource = self::execute($query);
		if(!$resource){
			die("Could not query".mysql_error());
		}
		return mysql_result($resource, 0);
	}
	
	/**
	 * Returns the number of rows in an result set
	 */
	public static function getNumRows($query){
		$resource = self::execute($query);
		if(!$resource){
			die("Could not query".mysql_error());
		}
		return mysql_num_rows($resource);
	}
}